package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Enquiry;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.query.EnquiryDetailQuery;
import com.by.query.EnquiryQuery;
import com.by.service.EnquiryDetailService;
import com.by.service.EnquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(tags = "客户询价")
@RequestMapping("/v1")
public class EnquiryController extends BaseController {
    @Autowired
    EnquiryService enquiryService;
    @Autowired
    EnquiryDetailService enquiryDetailService;


    @ApiOperation("保存询价单")
    @PostMapping("/enquiry")
    public ResultBean save(@RequestBody Enquiry enquiry){
        int rs=enquiryService.save(enquiry);
        return saveResult(rs);
    }
    @ApiOperation("询价单列表")
    @PostMapping("/enquiry/query")
    public ResultBean queryAll(@RequestBody EnquiryQuery query) {
        Map map = BeanUtil.beanToMap(query);
        PageBean bean = enquiryService.query(map);
        return success("询价单列表", bean);
    }
    @ApiOperation("询价单详情")
    @PostMapping("/enquiry/detail")
    public ResultBean detail(@RequestBody EnquiryDetailQuery query) {
        Map map = BeanUtil.beanToMap(query);
        PageBean bean = enquiryDetailService.query(map);
        return success("询价单详情", bean);
    }
}
